import { onMounted, ref } from 'vue';
import type { SelectNowVersionVO } from '@/pages/application/configApp/apVersion/ApVersionTypes';
import type { R } from '@/types/R';
import { request } from '@/utils/Request';
import type { KeyValue } from '@/types/KeyValueType';
import { keyValueGetByKey } from '@/utils/KeyValueUtils';

export const usePropagateHooks = function(){

    let selectNowVersionVO = ref<SelectNowVersionVO>()

    onMounted(async()=>{
        let r:R<SelectNowVersionVO> = await request.post("/appVersion/selectNowVersion")
        if(r.code == "success"){
            selectNowVersionVO.value = r.data
        }
    })

    const infoFormat = (info:string):string[]=>{
        let list:string[] = info?.split(/[\r\n]+/g)
        return list;
    }

    const toWeb = async ()=>{
        let keyValue:KeyValue = await keyValueGetByKey("web_url")
        window.open(keyValue.value1, "_blank")
    }
    
    return {
        selectNowVersionVO,
        infoFormat,
        toWeb
    }
}